package com.qianbao.qianbaobusiness.ui.mine.qrcode;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.androidbase.utils.AndroidUtils;
import com.baseandroid.config.Constant;
import com.baseandroid.mvp.BaseMvpActivity;
import com.qianbao.qianbaobusiness.R;
import com.qianbao.qianbaobusiness.json.JumpBean;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * 支付状态页面
 */
public class PayResultActivity extends BaseMvpActivity<PayResultView,PayResultPresenter>{
    @BindView(R.id.toolbar_back)
    RelativeLayout toolbarBack ;       //返回
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle ; //标题
    @BindView(R.id.right_text)
    TextView rightText ;    //完成
    @BindView(R.id.img_pay_result)
    ImageView imgPayResult ;
    @BindView(R.id.tv_pay_result)
    TextView tvPayResult ;


    private String mStatus ;
    @Override
    protected int getLayoutId() {
        return R.layout.pay_result_activity;
    }

    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected void setupView() {
        EventBus.getDefault().register(this);
        toolbarTitle.setText(AndroidUtils.getContext().getResources().getString(R.string.qr_bind));
        rightText.setVisibility(View.VISIBLE);
        rightText.setText(getApplicationContext().getResources().getString(R.string.complete));
        rightText.setTextColor(getApplicationContext().getResources().getColor(R.color.text_important));
    }

    @Override
    protected void setupData(Bundle savedInstanceState) {
        mStatus = getIntent().getStringExtra("code");
        switch (mStatus){
            case Constant.PAY_SUCCESS :
                tvPayResult.setText(getApplicationContext().getResources().getString(R.string.pay_success));
                imgPayResult.setImageDrawable(getApplicationContext().getResources().getDrawable(R.drawable.pau_success));

                break;

            case Constant.PAY_FAILED :
                tvPayResult.setText(getApplicationContext().getResources().getString(R.string.pay_failed));
                imgPayResult.setImageDrawable(getApplicationContext().getResources().getDrawable(R.drawable.pay_failed));
                break;
        }
    }

    @OnClick({R.id.toolbar_back,R.id.right_text})
    public void OnClick(View view){
        switch (view.getId()){
            case R.id.toolbar_back :    //返回
                    finish();
                break;

            case R.id.right_text :      //完成
                    EventBus.getDefault().post(new JumpBean("complete"));
                    finish();
                break;
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEvent(String string){

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}
